/* MOS                                                        */
/* Giordano Mion, Luca David Opromolla and Alessandro Sforza  */
/* University of Sussex, Banco de Portugal & NC State, and Bologna       */

program drop _all
clear all
clear matrix
capture log close
set more off
local path = "/Users/lucadavidopromolla/Projects/MOS_rev"
cd "`path'/computation"
log using "`path'/logs/MOS_plots_Apr_27_2022_rev.log", replace
set mem 12g
set matsize 7500
set scheme s1color
set scheme plotplainblind

// Load data and merge with common dataset (to use same set of observations in all regressions, by product and by destination)
use MMT_trade_status_entryb_s.dta, clear
merge m:1 empresa ano using common_dataset
keep if _merge==3
drop _merge
cap drop __000000
egen firm_year_tag = tag(empresa ano)
save ang,replace

//////////// Plots ////////////

// Add back 2001
/*
use destinations1,clear
keep ano empresa de_ang
rename de_ang de_
gen dest = 8
keep if ano==2001
sort empresa ano dest
save trang01,replace
use ang,clear
keep if ano==2000 & dest==8
replace ano = 2001
drop de_
sort empresa ano dest
merge 1:1 empresa ano dest using trang01
keep if _merge==3 // merge should never be 1
drop _merge
save ang01,replace
*/
use ang,clear
sort empresa
merge empresa using bsample
keep if _merge==3
drop _merge
*append using ang01
save plot_ang01,replace
// P1. Entry Rate for firms with and without manager with export experience to Angola
use plot_ang01,clear
keep if dest==8 & ano<=2005
sort empresa dest ano
gen entry = (de_==1 & de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the firm can enter into a new destination
sort empresa dest ano
keep if (de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0)
save plot_ang01_data,replace
collapse (mean) entry_share=entry,by(ano dest mkt_spec_exp)
twoway (scatter entry_share ano if dest==8 & mkt_spec_exp==0, cmissing(no) lcolor(gs4) lpattern(dash) sort cmissing(no)) || (scatter entry_share ano if dest==8 & mkt_spec_exp>0 & mkt_spec_exp!=.,lcolor(gs0) cmissing(no) lpattern(solid) sort  xlab(1997(1)2005,labsize(small) angle(45)) ylab(0(0.05)0.2,labsize(small) nogrid) legend(order(1 2) label(1 "No Specific Export Experience") label(2 "With Specific Export Experience")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Export entry rate,size(small)) xtitle(Year,size(small)) text( 0.07 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text( 0.055 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text( 0.11 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(midblue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_entry.gph",replace))
graph export "`path'/results/graphs/agg_entry.eps", as(eps) fontface(Times) replace
graph export "`path'/results/graphs/agg_entry.pdf", as(pdf) fontface(Times) replace


// P1 alternative
use data_ang,clear
sort empresa
merge empresa using bsample
keep if _merge==3
drop _merge
*append using ang01
collapse (mean) entry_share=entry,by(ano mkt_spec_exp)
twoway (scatter entry_share ano if mkt_spec_exp==0, cmissing(no) lcolor(gs4) lpattern(dash) sort cmissing(no)) || (scatter entry_share ano if mkt_spec_exp>0 & mkt_spec_exp!=.,lcolor(gs0) cmissing(no) lpattern(solid) sort  xlab(1997(1)2005,labsize(small) angle(45)) ylab(0(0.05)0.2,labsize(small) nogrid) legend(order(1 2) label(1 "No Specific Export Experience") label(2 "With Specific Export Experience")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Export entry rate,size(small)) xtitle(Year,size(small)) text( 0.07 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text( 0.055 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text( 0.11 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(midblue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_entry.gph",replace))
graph export "`path'/results/graphs/agg_entry.eps", as(eps) fontface(Times) replace
graph export "`path'/results/graphs/agg_entry.pdf", as(pdf) fontface(Times) replace
// P1 alternative two
use data_ang,clear
keep if ano>=1997 & ano<=2005
gen ymkt_spec_exp = mkt_spec_exp>0 & mkt_spec_exp!=.
replace ymkt_spec_exp = . if mkt_spec_exp==.
label define ymkt_spec_exp 0 "No Manager with Export Experience to Angola" 1 "At Least One Manager with Export Experience to Angola"
label values ymkt_spec_exp ymkt_spec_exp
replace ano = ano-1 if ano>=2002
reg entry ano#ymkt_spec_exp, vce(cluster empresa)
margins ano#ymkt_spec_exp
marginsplot, recast(line)  recastci(rarea) ytitle(Average Entry Rate) xtitle(year) legend(position(6)) title("")
graph export "`path'/results/graphs/desc_er_plot.eps", as(eps) fontface(Times) replace
graph export "`path'/results/graphs/desc_er_plot.pdf", as(pdf) fontface(Times) replace






// Controlling for sector*year dummies, firm size and productivity
use plot_ang01_data,clear
reg entry i.nace##i.ano relsize relapp_lbprod
predict entryp,res
drop entry
rename entryp entry
collapse (mean) entry_share=entry,by(ano dest mkt_spec_exp)
twoway (scatter entry_share ano if dest==8 & mkt_spec_exp==0, cmissing(no) lcolor(gs4) lpattern(dash) sort cmissing(no)) || (scatter entry_share ano if dest==8 & mkt_spec_exp>0 & mkt_spec_exp!=., lcolor(gs0) cmissing(no) lpattern(solid) sort  xlab(1997(1)2005,labsize(small) angle(45)) ylab(0(0.025)0.1,labsize(small) nogrid) legend(order(1 2) label(1 "No Specific Export Experience") label(2 "With Specific Export Experience")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Export entry rate,size(small)) xtitle(Year,size(small)) text( 0.07 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text( 0.055 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text( 0.09 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(midblue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs//agg_entry.gph",replace))
/*// P1. Entry Rate for firms with and without manager with export experience to Angola - experience in the previous 2 years
use plot_ang01,clear
keep if dest==8 & ano<=2005
sort empresa dest ano
gen entry = (de_==1 & de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the firm can enter into a new destination
sort empresa dest ano
keep if (de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0)
save plot_ang01_data,replace
collapse (mean) entry_share=entry,by(ano dest r2mkt_spec_exp)
twoway (scatter entry_share ano if dest==8 & r2mkt_spec_exp==0, cmissing(no) lcolor(gs4) lpattern(dash) sort cmissing(no)) || (scatter entry_share ano if dest==8 & r2mkt_spec_exp>0 & r2mkt_spec_exp!=.,lcolor(gs0) cmissing(no) lpattern(solid) sort  xlab(1997(1)2005,labsize(small) angle(45)) ylab(0(0.05)0.2,labsize(small) nogrid) legend(order(1 2) label(1 "No Specific Export Experience") label(2 "With Specific Export Experience")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Export entry rate,size(small)) xtitle(Year,size(small)) text( 0.07 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text( 0.055 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text( 0.11 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(midblue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_entry_r2.gph",replace))
graph export "`path'/results/graphs//agg_entry_r2.eps", as(eps) fontface(Times) replace
graph export "`path'/results/graphs//agg_entry_r2.pdf", as(pdf) fontface(Times) replace
// Controlling for sector*year dummies, firm size and productivity
use plot_ang01_data,clear
reg entry i.nace##i.ano relsize relapp_lbprod
predict entryp,res
drop entry
rename entryp entry
collapse (mean) entry_share=entry,by(ano dest r2mkt_spec_exp)
twoway (scatter entry_share ano if dest==8 & r2mkt_spec_exp==0, cmissing(no) lcolor(gs4) lpattern(dash) sort cmissing(no)) || (scatter entry_share ano if dest==8 & r2mkt_spec_exp>0 & r2mkt_spec_exp!=., lcolor(gs0) cmissing(no) lpattern(solid) sort  xlab(1997(1)2005,labsize(small) angle(45)) ylab(0(0.025)0.1,labsize(small) nogrid) legend(order(1 2) label(1 "No Specific Export Experience") label(2 "With Specific Export Experience")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Export entry rate,size(small)) xtitle(Year,size(small)) text( 0.07 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text( 0.055 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text( 0.09 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(midblue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_entry_r2.gph",replace))
// P1. Entry Rate for firms with and without manager with export experience to Angola - experience in the previous 3 years
use plot_ang01,clear
keep if dest==8 & ano<=2005
sort empresa dest ano
gen entry = (de_==1 & de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the firm can enter into a new destination
sort empresa dest ano
keep if (de_[_n-1]==0 & empresa==empresa[_n-1] & dest==dest[_n-1] & other_exporter==0)
save plot_ang01_data,replace
collapse (mean) entry_share=entry,by(ano dest r3mkt_spec_exp)
twoway (scatter entry_share ano if dest==8 & r3mkt_spec_exp==0, cmissing(no) lcolor(gs4) lpattern(dash) sort cmissing(no)) || (scatter entry_share ano if dest==8 & r3mkt_spec_exp>0 & r3mkt_spec_exp!=.,lcolor(gs0) cmissing(no) lpattern(solid) sort  xlab(1997(1)2005,labsize(small) angle(45)) ylab(0(0.05)0.2,labsize(small) nogrid) legend(order(1 2) label(1 "No Specific Export Experience") label(2 "With Specific Export Experience")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Export entry rate,size(small)) xtitle(Year,size(small)) text( 0.07 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text( 0.055 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text( 0.11 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(midblue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs//agg_entry_r3.gph",replace))
graph export "`path'/results/graphs//agg_entry_r3.eps", as(eps) fontface(Times) replace
graph export "`path'/results/graphs//agg_entry_r3.pdf", as(pdf) fontface(Times) replace
// Controlling for sector*year dummies, firm size and productivity
use plot_ang01_data,clear
reg entry i.nace##i.ano relsize relapp_lbprod
predict entryp,res
drop entry
rename entryp entry
collapse (mean) entry_share=entry,by(ano dest r3mkt_spec_exp)
twoway (scatter entry_share ano if dest==8 & r3mkt_spec_exp==0, cmissing(no) lcolor(gs4) lpattern(dash) sort cmissing(no)) || (scatter entry_share ano if dest==8 & r3mkt_spec_exp>0 & r3mkt_spec_exp!=., lcolor(gs0) cmissing(no) lpattern(solid) sort  xlab(1997(1)2005,labsize(small) angle(45)) ylab(0(0.025)0.1,labsize(small) nogrid) legend(order(1 2) label(1 "No Specific Export Experience") label(2 "With Specific Export Experience")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle(Export entry rate,size(small)) xtitle(Year,size(small)) text( 0.07 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text( 0.055 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text( 0.09 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(midblue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_entry_r3.gph",replace))
*/

// P2. Total Exports to Angola
use destinations2,clear
sort npc_alt ano
merge 1:m npc_alt ano using ang
keep if _merge==3
drop _merge
keep ano npc_alt v_est_ang
collapse (max) v_est_,by(npc_alt ano)
collapse (sum) v_est_,by(ano)
gen double tot_exp0t = v_est_ if ano==1996
egen double tot_exp0 = max(tot_exp0t)
gen double tot_exp = v_est_/tot_exp0
replace ano = ano-1 if ano>=2002
// Plot whose year labels need to be manually edited (there is no easy way to do this automatically in Stata)
twoway (line tot_exp ano if ano<=2000, cmissing(no) lcolor(gs6) lpattern(solid) lwidth(medthick) sort) || (line tot_exp ano if ano>=2001, cmissing(no) lcolor(gs6) lpattern(solid) lwidth(medthick) sort) || (lfit tot_exp ano if ano<=2000,  lcolor(cranberry) lpattern(dash) cmissing(n)) || (lfit tot_exp ano if ano>=2001,  lcolor(blue) lpattern(dash) cmissing(n) xlab(1996 1997 1998 1999 2000 2001 2002 2003 2004,labsize(small) angle(45)) ylab(0(0.5)4,labsize(small) grid) legend(order(1 2 3 4) label(1 "Aggregate Exports") label(2 "") label(3 "Linear Fit Before 2002") label(4 "Linear Fit After 2002")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports, Normalized to One in 1996",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_exp.gph",replace))
graph export "`path'/results/graphs/agg_exp.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/agg_exp.eps", as(eps) fontface(Times) replace
/*
twoway (line tot_exp ano if ano<=2000, cmissing(no) lcolor(gs6) lpattern(solid) lwidth(medthick) sort) || (line tot_exp ano if ano>=2002, cmissing(no) lcolor(gs6) lpattern(solid) lwidth(medthick) sort) || (lfit tot_exp ano if ano<=2000,  lcolor(cranberry) lpattern(dash) cmissing(n)) || (lfit tot_exp ano if ano>=2002,  lcolor(blue) lpattern(dash) cmissing(n) xlab(1996 1997 1998 1999 2000 2002 2003 2004 2005,labsize(small) angle(45)) ylab(0(0.5)4,labsize(small) grid) legend(order(1 2 3 4) label(1 "Aggregate Exports") label(2 "") label(3 "Linear Fit Before 2002") label(4 "Linear Fit After 2002")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports, Normalized to One in 1996",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving(graphs/agg_exp.gph,replace))
graph export "graphs/agg_exp.pdf", as(pdf) fontface(Times) replace
graph export "graphs/agg_exp.eps", as(eps) fontface(Times) replace
twoway (line tot_exp ano, cmissing(no) lcolor(gs6) lpattern(solid) lwidth(medthick) sort) || (lfit tot_exp ano if ano<=2000,  lcolor(cranberry) lpattern(dash)) || (lfit tot_exp ano if ano>=2002,  lcolor(blue) lpattern(dash) xlab(1996(1)2005,labsize(small) angle(45)) ylab(0(0.5)4,labsize(small) grid) legend(order(1 3 4) label(1 "Aggregate Exports") label(3 "Linear Fit Before 2002") label(4 "Linear Fit After 2002")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports, Normalized to One in 1996",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving(graphs/agg_exp_cl.gph,replace))
graph export "graphs/agg_exp_cl.pdf", as(pdf) fontface(Times) replace
graph export "graphs/agg_exp_cl.eps", as(eps) fontface(Times) replace
*/
// Alternative: using 2001
use destinations2,clear
keep ano npc_alt v_est_ang
keep if ano>=1995 & ano<=2005
collapse (max) v_est_,by(npc_alt ano)
collapse (sum) v_est_,by(ano)
gen double tot_exp0t = v_est_ if ano==1995
egen double tot_exp0 = max(tot_exp0t)
gen double tot_exp = v_est_/tot_exp0
// Plot whose year labels need to be manually edited (there is no easy way to do this automatically in Stata)
twoway (line tot_exp ano, cmissing(no) lcolor(gs6) lpattern(solid) lwidth(medthick) sort) || (lfit tot_exp ano if ano<=2001,  lcolor(cranberry) lpattern(dash) cmissing(n)) || (lfit tot_exp ano if ano>=2002,  lcolor(blue) lpattern(dash) cmissing(n) xlab(1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005,labsize(small) angle(45)) ylab(0(0.5)4,labsize(small) grid) legend(order(1 2 3 4) label(1 "Aggregate Exports") label(2 "") label(3 "Linear Fit Before 2002") label(4 "Linear Fit After 2002")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports, Normalized to One in 1996",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_exp_alt.gph",replace))
graph export "`path'/results/graphs/agg_exp_alt.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/agg_exp_alt.eps", as(eps) fontface(Times) replace
// Alternative 2 using 2001
use "`path'/computation/Tdata.dta",clear
keep v_est npc_alt ano fluxo pais
collapse (sum) v_est,by(npc_alt ano fluxo pais)
reshape wide v_est, i(npc_alt ano pais) j(fluxo)
save P1_plot,replace
use P1_plot,clear
drop v_est1
keep if ano>=1995 & ano<=2005
gen colonies = 1 if pais==330
drop if colonies==.
collapse (sum) v_est2,by(ano colonies)
reshape wide v_est2,i(ano) j(colonies)
rename v_est21 v_est_ang
collapse (sum) v_est_,by(ano)
gen double tot_exp0t = v_est_ if ano==1995
egen double tot_exp0 = max(tot_exp0t)
gen double tot_exp = v_est_/tot_exp0
// Plot whose year labels need to be manually edited (there is no easy way to do this automatically in Stata)
twoway (line tot_exp ano, cmissing(no) lcolor(gs6) lpattern(solid) lwidth(medthick) sort) || (lfit tot_exp ano if ano<=2001,  lcolor(cranberry) lpattern(dash) cmissing(n)) || (lfit tot_exp ano if ano>=2002,  lcolor(blue) lpattern(dash) cmissing(n) xlab(1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005,labsize(small) angle(45)) ylab(0.5(0.5)3.5,labsize(small) grid) legend(order(1 2 3 4) label(1 "Aggregate Exports") label(2 "") label(3 "Linear Fit Before 2002") label(4 "Linear Fit After 2002")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports, Normalized to One in 1996",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_exp_alt.gph",replace))
graph export "`path'/results/graphs/agg_exp_alt.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/agg_exp_alt.eps", as(eps) fontface(Times) replace
replace v_est_ = v_est_/1000000
twoway (line v_est_ ano, cmissing(no) lcolor(gs6) lpattern(solid) lwidth(medthick) sort) || (lfit v_est_ ano if ano<=2001,  lcolor(cranberry) lpattern(dash) cmissing(n)) || (lfit v_est_ ano if ano>=2002,  lcolor(blue) lpattern(dash) cmissing(n) xlab(1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005,labsize(small) angle(45)) ylab(#6,labsize(small) grid) legend(order(1 2 3) label(1 "Aggregate Exports") label(2 "Linear Fit Before 2002") label(3 "Linear Fit After 2002")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports, Millions Euro",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_exp_alt_euro.gph",replace))
graph export "`path'/results/graphs/agg_exp_alt_euro.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/agg_exp_alt_euro.eps", as(eps) fontface(Times) replace

// P3. Total Exports to Angola, Entering vs. Continuing Firms
use destinations2,clear
sort npc_alt ano
merge 1:m npc_alt ano using ang
keep if _merge==3
drop _merge
keep if dest==8
sort npc_alt dest ano
gen entry = (de_==1 & de_[_n-1]==0 & npc_alt==npc_alt[_n-1] & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the firm can enter into a new destination
replace entry = 0 if (de_==1 & de_[_n-1]==1 & npc_alt==npc_alt[_n-1] & dest==dest[_n-1] & other_exporter==0) // Keep only period in which the firm can enter into a new destination
keep ano npc_alt v_est_ang entry
collapse (sum) v_est_ang,by(ano entry)
reshape wide v_est_ang,i(ano) j(entry)
gen double tot_exp00t = v_est_ang0 if ano==1997
gen double tot_exp01t = v_est_ang1 if ano==1997
egen double tot_exp00 = max(tot_exp00t)
egen double tot_exp01 = max(tot_exp01t)
gen double tot_exp0 = v_est_ang0/1000000
gen double tot_exp1 = v_est_ang1/1000000
keep if ano>=1997
twoway (line tot_exp1 ano if ano<=2000, lcolor(gs0) lpattern(solid)) || (line tot_exp1 ano if ano>=2002, lcolor(gs0) lpattern(solid)) || (line tot_exp0 ano if ano<=2000, cmissing(no) lcolor(gs6) lpattern(dash) lwidth(medthick))  || (line tot_exp0 ano if ano>=2002, cmissing(no) lcolor(gs6) lpattern(dash) lwidth(medthick) sort xlab(1997(1)2005,labsize(small) angle(45)) ylab(20(20)180,labsize(small) grid) legend(order(1 3) label(1 "Aggregate Exports - Entering Firms") label(3 "Aggregate Exports - Continuing Firms")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports (Millions Euros)",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(60 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(50 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(100 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_exp_entry.gph",replace))
graph export "`path'/results/graphs/agg_exp_entry.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/agg_exp_entry.eps", as(eps) fontface(Times) replace
twoway (line tot_exp1 ano, lcolor(gs0) lpattern(solid)) || (line tot_exp0 ano, cmissing(no) lcolor(gs6) lpattern(dash) lwidth(medthick) sort xlab(1997(1)2005,labsize(small) angle(45)) ylab(20(20)180,labsize(small) grid) legend(order(1 2) label(1 "Aggregate Exports - Entering Firms") label(3 "Aggregate Exports - Continuing Firms")  size(small) region(lcolor(white)) rows(1) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports (Millions Euros)",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(60 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(50 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(100 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_exp_entry_cl.gph",replace))
graph export "`path'/results/graphs/agg_exp_entry_cl.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/agg_exp_entry_cl.eps", as(eps) fontface(Times) replace


// P4. Total Exports to Angola and to Other Ex-colonies
use destinations2,clear
keep ano npc_alt v_est_ang v_est_cv v_est_gw v_est_st v_est_mz v_est_br v_est_tl
sort npc_alt ano
merge 1:m npc_alt ano using ang
keep if _merge==3
drop _merge
gen double v_est_oth = v_est_cv + v_est_gw + v_est_st + v_est_mz + v_est_br + v_est_tl
collapse (max) v_est_ang v_est_oth,by(npc_alt ano)
collapse (sum) v_est_ang v_est_oth,by(ano)
gen double tot_exp0t = v_est_ang if ano==1996
egen double tot_exp0 = max(tot_exp0t)
gen double tot_exp = v_est_ang/tot_exp0
gen double tot_exp0t_o = v_est_oth if ano==1996
egen double tot_exp0_o = max(tot_exp0t_o)
gen double tot_exp_o = v_est_oth/tot_exp0_o
replace tot_exp = tot_exp
replace tot_exp_o = tot_exp_o
replace ano = ano-1 if ano>=2002
// Plot whose year labels need to be manually edited (there is no easy way to do this automatically in Stata)
twoway (line tot_exp ano if ano<=2000, cmissing(no) lcolor(gs4) lpattern(solid) lwidth(medthick) sort) || (line tot_exp ano if ano>=2001, cmissing(no) lcolor(gs4) lpattern(solid) lwidth(medthick) sort) ||  || (line tot_exp_o ano if ano<=2000, cmissing(no) lcolor(gs0) lpattern(dash) lwidth(medthick) sort) || (line tot_exp_o ano if ano>=2001, cmissing(no) lcolor(gs0) lpattern(dash) lwidth(medthick) sort xlab(1996(1)2004,labsize(small) angle(45)) ylab(#6,labsize(small) grid) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) legend(order(1 3) label(1 "Angola") label(3 "Other Ex-colonies")  size(small) region(lcolor(white)) rows(1) pos(6)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports, Normalized to One in 1996",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_exp_control.gph",replace))
graph export "`path'/results/graphs/agg_exp_control.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/agg_exp_control.eps", as(eps) fontface(Times) replace
/*
twoway (line tot_exp ano if ano<=2000, cmissing(no) lcolor(gs4) lpattern(solid) lwidth(medthick) sort) || (line tot_exp ano if ano>=2002, cmissing(no) lcolor(gs4) lpattern(solid) lwidth(medthick) sort) ||  || (line tot_exp_o ano if ano<=2000, cmissing(no) lcolor(gs0) lpattern(dash) lwidth(medthick) sort) || (line tot_exp_o ano if ano>=2002, cmissing(no) lcolor(gs0) lpattern(dash) lwidth(medthick) sort xlab(1996(1)2005,labsize(small) angle(45)) ylab(#6,labsize(small) grid) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) legend(order(1 3) label(1 "Angola") label(3 "Other Ex-colonies")  size(small) region(lcolor(white)) rows(1) pos(6)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports, Normalized to One in 1996",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving(graphs/agg_exp_control.gph,replace))
graph export "graphs/agg_exp_control.pdf", as(pdf) fontface(Times) replace
graph export "graphs/agg_exp_control.eps", as(eps) fontface(Times) replace
twoway (line tot_exp ano, cmissing(no) lcolor(gs4) lpattern(solid) lwidth(medthick) sort) ||  || (line tot_exp_o ano, cmissing(no) lcolor(gs0) lpattern(dash) lwidth(medthick) sort xlab(1996(1)2005,labsize(small) angle(45)) ylab(#6,labsize(small) grid) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) legend(order(1 3) label(1 "Angola") label(3 "Other Ex-colonies")  size(small) region(lcolor(white)) rows(1) pos(6)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports, Normalized to One in 1996",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving(graphs/agg_exp_control_cl.gph,replace))
graph export "graphs/agg_exp_control_cl.pdf", as(pdf) fontface(Times) replace
graph export "graphs/agg_exp_control_cl.eps", as(eps) fontface(Times) replace
*/
// Alternative using 2001
use destinations2,clear
keep ano npc_alt v_est_ang v_est_cv v_est_gw v_est_st v_est_mz v_est_br v_est_tl
keep if ano>=1995 & ano<=2005
gen double v_est_oth = v_est_cv + v_est_gw + v_est_st + v_est_mz + v_est_br + v_est_tl
collapse (max) v_est_ang v_est_oth,by(npc_alt ano)
collapse (sum) v_est_ang v_est_oth,by(ano)
gen double tot_exp0t = v_est_ang if ano==1995
egen double tot_exp0 = max(tot_exp0t)
gen double tot_exp = v_est_ang/tot_exp0
gen double tot_exp0t_o = v_est_oth if ano==1995
egen double tot_exp0_o = max(tot_exp0t_o)
gen double tot_exp_o = v_est_oth/tot_exp0_o
replace tot_exp = tot_exp
replace tot_exp_o = tot_exp_o
// Plot whose year labels need to be manually edited (there is no easy way to do this automatically in Stata)
twoway (line tot_exp ano, cmissing(no) lcolor(gs4) lpattern(solid) lwidth(medthick) sort)   || (line tot_exp_o ano, cmissing(no) lcolor(gs0) lpattern(dash) lwidth(medthick) sort xlab(1995(1)2005,labsize(small) angle(45)) ylab(#6,labsize(small) grid) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) legend(order(1 2) label(1 "Angola") label(2 "Other Ex-colonies")  size(small) region(lcolor(white)) rows(1) pos(6)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports, Normalized to One in 1996",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_exp_control_alt.gph",replace))
graph export "`path'/results/graphs/agg_exp_control_alt.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/agg_exp_control_alt.eps", as(eps) fontface(Times) replace
// Alternative 2 using 2001
use "`path'/computation/Tdata.dta",clear
keep v_est npc_alt ano fluxo pais
collapse (sum) v_est,by(npc_alt ano fluxo pais)
reshape wide v_est, i(npc_alt ano pais) j(fluxo)
save P1_plot,replace
use P1_plot,clear
drop v_est1
keep if ano>=1995 & ano<=2005
gen colonies = 1 if pais==330
replace colonies = 2 if (pais==247 | pais==257 | pais==311 | pais==366 | pais==508 | pais==699)
drop if colonies==.
collapse (sum) v_est2,by(ano colonies)
reshape wide v_est2,i(ano) j(colonies)
rename v_est21 v_est_ang
rename v_est22 v_est_oth 
gen double tot_exp0t = v_est_ang if ano==1996
egen double tot_exp0 = max(tot_exp0t)
gen double tot_exp = v_est_ang/tot_exp0
gen double tot_exp0t_o = v_est_oth if ano==1996
egen double tot_exp0_o = max(tot_exp0t_o)
gen double tot_exp_o = v_est_oth/tot_exp0_o
replace tot_exp = tot_exp
replace tot_exp_o = tot_exp_o
// Plot whose year labels need to be manually edited (there is no easy way to do this automatically in Stata)
twoway (line tot_exp ano, cmissing(no) lcolor(gs4) lpattern(solid) lwidth(medthick) sort)   || (line tot_exp_o ano, cmissing(no) lcolor(gs0) lpattern(dash) lwidth(medthick) sort xlab(1995(1)2005,labsize(small) angle(45)) ylab(#6,labsize(small) grid) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) legend(order(1 2) label(1 "Angola") label(2 "Other Ex-colonies")  size(small) region(lcolor(white)) rows(1) pos(6)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Aggregate Exports, Normalized to One in 1996",size(small)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving("`path'/results/graphs/agg_exp_control_alt.gph",replace))
graph export "`path'/results/graphs/agg_exp_control_alt.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/agg_exp_control_alt.eps", as(eps) fontface(Times) replace

local path = "/Users/lucadavidopromolla/Projects/MOS_rev"

// P5. Entry rate by type of manager experience (no export experience, destination exp., product exp., and product-destination exp.)
use destinations1_ap,clear
keep ano npc_alt de_ang*
drop de_ang
reshape long de_ang, i(npc_alt ano) j(isic)
rename de_ang de_
keep if ano==2001
sort npc_alt ano isic
save trang01_ap,replace
use data_ang_prmk,clear
keep if ano==2000 & isic>14
replace ano = 2001
drop de_
sort npc_alt ano isic
merge 1:1 npc_alt ano isic using trang01_ap
keep if _merge==3 // merge should never be 1
drop _merge
save ang01_ap,replace
use data_ang_prmk,clear
append using ang01_ap
save plot_ang01_ap,replace
// Full history experience
use plot_ang01_ap,clear
gen cat = 0 if mkt_spec_exp==0 & prgr_spec_exp==0 & prmk_spec_exp==0
replace cat = 1 if mkt_spec_exp>0 & prmk_spec_exp==0
replace cat = 2 if prgr_spec_exp>0 & prmk_spec_exp==0
replace cat = 3 if prgr_spec_exp>0 & prmk_spec_exp>0
label define cat 0 "No Experience" 1 "Destination Exp." 2 "Product Exp." 3 "Destination-product Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post 
collapse (mean) entry_share=entry,by(post isic cat)
reshape wide entry_share, i(isic cat) j(post)
graph bar entry_share0 entry_share1, over(cat,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2) label(1 "Pre-2002") label(2 "Post-2002") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "`path'/results/graphs/entry_rate_type.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/entry_rate_type.eps", as(eps) fontface(Times) replace
/*
// 2 years experience
use plot_ang01_ap,clear
gen cat = 0 if r2mkt_spec_exp==0 & r2prgr_spec_exp==0 & r2prmk_spec_exp==0
replace cat = 1 if r2mkt_spec_exp>0 & r2prmk_spec_exp==0
replace cat = 2 if r2prgr_spec_exp>0 & r2prmk_spec_exp==0
replace cat = 3 if r2prgr_spec_exp>0 & r2prmk_spec_exp>0
label define cat 0 "No Experience" 1 "Destination Exp." 2 "Product Exp." 3 "Destination-product Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post 
collapse (mean) entry_share=entry,by(post isic cat)
reshape wide entry_share, i(isic cat) j(post)
graph bar entry_share0 entry_share1, over(cat,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2) label(1 "Pre-2002") label(2 "Post-2002") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "`path'/results/graphs/entry_rate_type_r2.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/entry_rate_type_r2.eps", as(eps) fontface(Times) replace
// 3 years experience
use plot_ang01_ap,clear
gen cat = 0 if r3mkt_spec_exp==0 & r3prgr_spec_exp==0 & r3prmk_spec_exp==0
replace cat = 1 if r3mkt_spec_exp>0 & r3prmk_spec_exp==0
replace cat = 2 if r3prgr_spec_exp>0 & r3prmk_spec_exp==0
replace cat = 3 if r3prgr_spec_exp>0 & r3prmk_spec_exp>0
label define cat 0 "No Experience" 1 "Destination Exp." 2 "Product Exp." 3 "Destination-product Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post 
collapse (mean) entry_share=entry,by(post isic cat)
reshape wide entry_share, i(isic cat) j(post)
graph bar entry_share0 entry_share1, over(cat,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2) label(1 "Pre-2002") label(2 "Post-2002") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "`path'/results/graphs/entry_rate_type_r3.pdf", as(pdf) fontface(Times) replace
graph export "`path'/results/graphs/entry_rate_type_r3.eps", as(eps) fontface(Times) replace


// P6. Change in entry rate (pre vs. post) by product differentiation, normalized by change of entry rate for firms without any manager with export experience.
use plot_ang01_ap,clear
gen cat = 0 if mkt_spec_exp==0 & prgr_spec_exp==0 & prmk_spec_exp==0
replace cat = 1 if mkt_spec_exp>0 & prmk_spec_exp==0
replace cat = 2 if prgr_spec_exp>0 & prmk_spec_exp==0
replace cat = 3 if prgr_spec_exp>0 & prmk_spec_exp>0
label define cat 0 "No Experience" 1 "Destination Exp." 2 "Product Exp." 3 "Destination-product Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post 
//gen cra = 1 if rauch_w<=0.1
//replace cra = 2 if rauch_w>0.1 & rauch_w<=0.5
//replace cra = 3 if rauch_w>0.5 & rauch_w!=.
//gen cra = 1 if rauch_w<=0.1
gen cra = 1 if rauch_w<=0.1
replace cra = 2 if rauch_w>0.1 & rauch_w!=.
collapse (mean) entry_share=entry (mean) cra,by(post isic cat)
reshape wide entry_share, i(isic cat) j(post)
reshape wide entry_share*, i(isic) j(cat)
gen double change1 = (entry_share11 - entry_share01) - (entry_share10 - entry_share00)
gen double change2 = (entry_share12 - entry_share02) - (entry_share10 - entry_share00)
gen double change3 = (entry_share13 - entry_share03) - (entry_share10 - entry_share00)
collapse (mean) change*,by(cra)
label define cra 1 "Homogeneous Products" 2 "Differentiated Products"
label values cra cra
graph bar change1 change2 change3, over(cra,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2 3) label(1 "Destination Exp.") label(2 "Product Exp.")  label(3 "Destination-Product Exp.") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "graphs/entry_rate_rauch.pdf", as(pdf) fontface(Times) replace
graph export "graphs/entry_rate_rauch.eps", as(eps) fontface(Times) replace
// P7. Avg. Exports given entry by type of manager experience (no export experience, destination exp., product exp., and product-destination exp.)
use destinations2_ap,clear
keep ano empresa v_est_ang*
drop v_est_ang
reshape long v_est_ang, i(empresa ano) j(isic)
rename v_est_ang v_est
keep if ano==2001
sort empresa ano isic
save trang01_ap,replace
use data_ang_prmk,clear
keep if ano==2000 & isic>14
replace ano = 2001
drop de_
sort empresa ano isic
merge 1:1 empresa ano isic using trang01_ap
keep if _merge==3 // merge should never be 1
drop _merge
save ang01_ap,replace
use data_ang_prmk,clear
rename v_est2 v_est
append using ang01_ap
save plot_ang01_ap,replace
use plot_ang01_ap,clear
sort empresa isic ano
keep if (entry==1 & empresa==empresa[_n-1] & isic==isic[_n-1] & other_exporter==0)
gen cat = 0 if mkt_spec_exp==0 & prgr_spec_exp==0 & prmk_spec_exp==0
replace cat = 1 if mkt_spec_exp>0 & prmk_spec_exp==0
replace cat = 2 if prgr_spec_exp>0 & prmk_spec_exp==0
replace cat = 3 if prgr_spec_exp>0 & prmk_spec_exp>0
label define cat 0 "No Experience" 1 "Destination Exp." 2 "Product Exp." 3 "Destination-product Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post
drop ln_exports
gen double ln_exports = log(v_est)
collapse (mean) ln_exports,by(post isic cat)
reshape wide ln_exports, i(isic cat) j(post)
graph bar ln_exports0 ln_exports1, over(cat,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2) label(1 "Pre-2002") label(2 "Post-2002") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "graphs/exports_given_entry_type.pdf", as(pdf) fontface(Times) replace
graph export "graphs/exports_given_entry_type.eps", as(eps) fontface(Times) replace
// P8. Change in avg. exports given entry (pre vs. post) by product differentiation, normalized by change of entry rate for firms without any manager with export experience.
use plot_ang01_ap,clear
gen cat = 0 if mkt_spec_exp==0 & prgr_spec_exp==0 & prmk_spec_exp==0
replace cat = 1 if mkt_spec_exp>0 & prmk_spec_exp==0
replace cat = 2 if prgr_spec_exp>0 & prmk_spec_exp==0
replace cat = 3 if prgr_spec_exp>0 & prmk_spec_exp>0
label define cat 0 "No Experience" 1 "Destination Exp." 2 "Product Exp." 3 "Destination-product Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post 
//gen cra = 1 if rauch_w<=0.1
//replace cra = 2 if rauch_w>0.1 & rauch_w<=0.5
//replace cra = 3 if rauch_w>0.5 & rauch_w!=.
//gen cra = 1 if rauch_w<=0.1
gen cra = 1 if rauch_w<=0.1
replace cra = 2 if rauch_w>0.1 & rauch_w!=.
drop ln_exports
gen double ln_exports = log(v_est)
collapse (mean) ln_exports (mean) cra,by(post isic cat)
reshape wide ln_exports, i(isic cat) j(post)
reshape wide ln_exports*, i(isic) j(cat)
gen double change1 = (ln_exports11 - ln_exports01) - (ln_exports10 - ln_exports00)
gen double change2 = (ln_exports12 - ln_exports02) - (ln_exports10 - ln_exports00)
gen double change3 = (ln_exports13 - ln_exports03) - (ln_exports10 - ln_exports00)
collapse (mean) change*,by(cra)
label define cra 1 "Homogeneous Products" 2 "Differentiated Products"
label values cra cra
graph bar change1 change2 change3, over(cra,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2 3) label(1 "Destination Exp.") label(2 "Product Exp.")  label(3 "Destination-Product Exp.") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "graphs/exports_given_entry_rauch.pdf", as(pdf) fontface(Times) replace
graph export "graphs/exports_given_entry_rauch.eps", as(eps) fontface(Times) replace
// P8alt. Change in avg. exports given entry (pre vs. post) by product differentiation, normalized by change of entry rate for firms without any manager with export experience.
use plot_ang01_ap,clear
gen cat = 0 if mkt_spec_exp==0 & prgr_spec_exp==0 & prmk_spec_exp==0
replace cat = 1 if mkt_spec_exp>0 & prmk_spec_exp==0
replace cat = 2 if prgr_spec_exp>0 & prmk_spec_exp==0
replace cat = 3 if prgr_spec_exp>0 & prmk_spec_exp>0
label define cat 0 "No Experience" 1 "Destination Exp." 2 "Product Exp." 3 "Destination-product Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post 
//gen cra = 1 if rauch_w<=0.1
//replace cra = 2 if rauch_w>0.1 & rauch_w<=0.5
//replace cra = 3 if rauch_w>0.5 & rauch_w!=.
//gen cra = 1 if rauch_w<=0.1
gen cra = 1 if rauch_w<=0.1
replace cra = 2 if rauch_w>0.1 & rauch_w!=.
drop ln_exports
gen double ln_exports = (v_est)
collapse (mean) ln_exports (mean) cra,by(post isic cat)
reshape wide ln_exports, i(isic cat) j(post)
reshape wide ln_exports*, i(isic) j(cat)
gen double change1 = ((ln_exports11 - ln_exports01)/(ln_exports11 + ln_exports01)/2) - ((ln_exports10 - ln_exports00)/(ln_exports10 + ln_exports00)/2)
gen double change2 = ((ln_exports12 - ln_exports02)/(ln_exports12 + ln_exports02)/2) - ((ln_exports10 - ln_exports00)/(ln_exports10 + ln_exports00)/2)
gen double change3 = ((ln_exports13 - ln_exports03)/(ln_exports13 + ln_exports03)/2) - ((ln_exports10 - ln_exports00)/(ln_exports10 + ln_exports00)/2)
collapse (mean) change*,by(cra)
label define cra 1 "Homogeneous Products" 2 "Differentiated Products"
label values cra cra
graph bar change1 change2 change3, over(cra,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2 3) label(1 "Destination Exp.") label(2 "Product Exp.")  label(3 "Destination-Product Exp.") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "graphs/exports_given_entry_rauch_alt.pdf", as(pdf) fontface(Times) replace
graph export "graphs/exports_given_entry_rauch_alt.eps", as(eps) fontface(Times) replace
// P9. Entry rate by type of manager experience (no export experience, destination exp., war exp.)
use destinations1,clear
keep ano empresa de_ang
keep if ano==2001
sort empresa ano
save trang01w,replace
use data_ang,clear
keep if ano==2000
replace ano = 2001
drop de_
sort empresa ano
merge 1:1 empresa ano using trang01w
keep if _merge==3 // merge should never be 1
drop _merge
save ang01w,replace
use data_ang,clear
append using ang01w
save plot_ang01w,replace
use plot_ang01w,clear
gen cat = 0 if mkt_spec_exp==0 & warexp==0
replace cat = 1 if mkt_spec_exp>0 & warexp==0
replace cat = 2 if mkt_spec_exp==0 & warexp>0
label define cat 0 "No Experience" 1 "Destination Exp." 2 "War Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post 
collapse (mean) entry_share=entry,by(post cat)
reshape wide entry_share, i(cat) j(post)
graph bar entry_share0 entry_share1, over(cat,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2) label(1 "Pre-2002") label(2 "Post-2002") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "graphs/entry_rate_typew.pdf", as(pdf) fontface(Times) replace
graph export "graphs/entry_rate_typew.eps", as(eps) fontface(Times) replace
// P10. Entry rate by type of manager experience (no export experience, war exp., destination exp., product exp., and product-destination exp.)
use destinations1_ap,clear
keep ano empresa de_ang*
drop de_ang
reshape long de_ang, i(empresa ano) j(isic)
rename de_ang de_
keep if ano==2001
sort empresa ano isic
save trang01_ap,replace
use data_ang_prmk,clear
keep if ano==2000 & isic>14
replace ano = 2001
drop de_
sort empresa ano isic
merge 1:1 empresa ano isic using trang01_ap
keep if _merge==3 // merge should never be 1
drop _merge
save ang01_ap,replace
use data_ang_prmk,clear
append using ang01_ap
save plot_ang01_ap,replace
use data_ang,clear
keep empresa ano warexp
sort empresa ano
save wexpv,replace
use plot_ang01_ap,clear
sort empresa ano
merge m:1 empresa ano using wexpv
keep if _merge==3
drop _merge
gen cat = 0 if mkt_spec_exp==0 & prgr_spec_exp==0 & prmk_spec_exp==0 & warexp==0
replace cat = 1 if mkt_spec_exp==0 & prgr_spec_exp==0 & prmk_spec_exp==0 & warexp>0
replace cat = 2 if mkt_spec_exp>0 & prmk_spec_exp==0 & warexp==0
replace cat = 3 if prgr_spec_exp>0 & prmk_spec_exp==0 & warexp==0
replace cat = 4 if prgr_spec_exp>0 & prmk_spec_exp>0 & warexp==0
label define cat 0 "No Experience" 1 "War experience" 2 "Destination Exp." 3 "Product Exp." 4 "Destination-product Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post 
collapse (mean) entry_share=entry,by(post isic cat)
reshape wide entry_share, i(isic cat) j(post)
graph bar entry_share0 entry_share1, over(cat,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2) label(1 "Pre-2002") label(2 "Post-2002") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "graphs/entry_rate_typew.pdf", as(pdf) fontface(Times) replace
graph export "graphs/entry_rate_typew.eps", as(eps) fontface(Times) replace
// P9B. Entry rate by type of manager experience (no export experience, destination exp., war exp.)
use destinations1,clear
keep ano empresa de_ang
keep if ano==2001
sort empresa ano
save trang01w,replace
use data_ang,clear
keep if ano==2000
replace ano = 2001
drop de_
sort empresa ano
merge 1:1 empresa ano using trang01w
keep if _merge==3 // merge should never be 1
drop _merge
save ang01w,replace
use data_ang,clear
append using ang01w
save plot_ang01w,replace
use plot_ang01w,clear
gen cat = 0 if mkt_spec_exp==0 & warexp==0
replace cat = 1 if mkt_spec_exp>0 & warexp==0
replace cat = 2 if mkt_spec_exp==0 & warexp>0
label define cat 0 "No Experience" 1 "Destination Exp." 2 "War Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post
reg entry i.ano
predict entryr,res
collapse (mean) entry_share=entryr,by(post cat)
reshape wide entry_share, i(cat) j(post)
graph bar entry_share0 entry_share1, over(cat,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2) label(1 "Pre-2002") label(2 "Post-2002") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "graphs/entry_rate_typew.pdf", as(pdf) fontface(Times) replace
graph export "graphs/entry_rate_typew.eps", as(eps) fontface(Times) replace
// P10B. Entry rate by type of manager experience (no export experience, war exp., destination exp., product exp., and product-destination exp.)
use destinations1_ap,clear
keep ano empresa de_ang*
drop de_ang
reshape long de_ang, i(empresa ano) j(isic)
rename de_ang de_
keep if ano==2001
sort empresa ano isic
save trang01_ap,replace
use data_ang_prmk,clear
keep if ano==2000 & isic>14
replace ano = 2001
drop de_
sort empresa ano isic
merge 1:1 empresa ano isic using trang01_ap
keep if _merge==3 // merge should never be 1
drop _merge
save ang01_ap,replace
use data_ang_prmk,clear
append using ang01_ap
save plot_ang01_ap,replace
use data_ang,clear
keep empresa ano warexp
sort empresa ano
save wexpv,replace
use plot_ang01_ap,clear
sort empresa ano
merge m:1 empresa ano using wexpv
keep if _merge==3
drop _merge
gen cat = 0 if mkt_spec_exp==0 & prgr_spec_exp==0 & prmk_spec_exp==0 & warexp==0
replace cat = 1 if mkt_spec_exp==0 & prgr_spec_exp==0 & prmk_spec_exp==0 & warexp>0
replace cat = 2 if mkt_spec_exp>0 & prmk_spec_exp==0 & warexp==0
replace cat = 3 if prgr_spec_exp>0 & prmk_spec_exp==0 & warexp==0
replace cat = 4 if prgr_spec_exp>0 & prmk_spec_exp>0 & warexp==0
label define cat 0 "No Experience" 1 "War experience" 2 "Destination Exp." 3 "Product Exp." 4 "Destination-product Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post
reg entry i.ano##i.isic
predict entryr,res
collapse (mean) entry_share=entryr,by(post isic cat)
reshape wide entry_share, i(isic cat) j(post)
graph bar entry_share0 entry_share1, over(cat,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2) label(1 "Pre-2002") label(2 "Post-2002") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "graphs/entry_rate_typewr.pdf", as(pdf) fontface(Times) replace
graph export "graphs/entry_rate_typewr.eps", as(eps) fontface(Times) replace
// P11. Number of products by type of manager experience (no export experience, war exp., destination exp., product exp., and product-destination exp.)
use destinations1_ap,clear
keep ano empresa de_ang*
drop de_ang
reshape long de_ang, i(empresa ano) j(isic)
rename de_ang de_
keep if ano==2001
sort empresa ano isic
save trang01_ap,replace
use data_ang_prmk,clear
keep if ano==2000 & isic>14
replace ano = 2001
drop de_
sort empresa ano isic
merge 1:1 empresa ano isic using trang01_ap
keep if _merge==3 // merge should never be 1
drop _merge
save ang01_ap,replace
use data_ang_prmk,clear
append using ang01_ap
save plot_ang01_ap,replace
use data_ang,clear
keep empresa ano warexp
sort empresa ano
save wexpv,replace
use plot_ang01_ap,clear
sort empresa ano
merge m:1 empresa ano using wexpv
keep if _merge==3
drop _merge
gen cat = 0 if mkt_spec_exp==0 & prgr_spec_exp==0 & prmk_spec_exp==0 & warexp==0
replace cat = 1 if mkt_spec_exp==0 & prgr_spec_exp==0 & prmk_spec_exp==0 & warexp>0
replace cat = 2 if mkt_spec_exp>0 & prmk_spec_exp==0 & warexp==0
replace cat = 3 if prgr_spec_exp>0 & prmk_spec_exp==0 & warexp==0
replace cat = 4 if prgr_spec_exp>0 & prmk_spec_exp>0 & warexp==0
label define cat 0 "No Experience" 1 "War experience" 2 "Destination Exp." 3 "Product Exp." 4 "Destination-product Exp."
label values cat cat
gen post = ano>=2002
label define post 0 "Pre-2002" 1 "Post-2002"
label values post post
drop if entry==0
collapse (mean) entry,by(post cat ano isic)
reg entry i.ano##i.isic
predict entryr,res
collapse (mean) entry_share=entryr,by(post cat)
reshape wide entry_share, i(cat) j(post)
graph bar entry_share0 entry_share1, over(cat,label(labsize(small))) bar(1,color(ltblue)) bar(2,color(ebblue)) legend(order(1 2) label(1 "Pre-2002") label(2 "Post-2002") size(small))   graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white))
graph export "graphs/entry_rate_typewr.pdf", as(pdf) fontface(Times) replace
graph export "graphs/entry_rate_typewr.eps", as(eps) fontface(Times) replace


/////////////////////////////////////
//////////// Summary stats //////////
/////////////////////////////////////

use data_ang,clear
// Number of potential entrants,by year and presence of export experience
table ano mkt_spec_exp ,c(count entry)
// Number of actual entrants,by year and presence of export experience
table ano mkt_spec_exp ,c(sum entry)
// Plot with the four measures above
preserve
collapse (sum) entrants=entry (count) pot_entrants=entry,by(ano mkt_spec_exp)
*twoway (line pot_entrants ano if mkt_spec_exp==0, cmissing(no) lcolor(gs6) lpattern(solid) lwidth(medthick) sort) || (line pot_entrants ano if mkt_spec_exp>0 & mkt_spec_exp!=., cmissing(no) lcolor(gs6) lpattern(dash) lwidth(medthick) sort  ylab(#6,labsize(vsmall) grid)) || (line entrants ano if mkt_spec_exp==0,  yaxis(2)  lcolor(cranberry) lpattern(solid)) || (line entrants ano if mkt_spec_exp>0 & mkt_spec_exp!=., yaxis(2)  lcolor(blue) lpattern(dash) xlab(1996(1)2005,labsize(small) angle(45)) ylab(#6,labsize(vsmall) grid) legend(order(1 2 3 4) label(1 "Potential Entrants - No Market Experience") label(2 "Potential Entrants - Market Experience") label(3 "Entrants - No Market Experience")  label(4 "Entrants - Market Experience")  size(small) region(lcolor(white)) rows(2) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Number of Potential and Actual Entrants",size(vsmall)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(2 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(1.5 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(3 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving(graphs/entrants.gph,replace))
twoway (line entrants ano if mkt_spec_exp==0,  lcolor(cranberry) lpattern(solid)) || (line entrants ano if mkt_spec_exp>0 & mkt_spec_exp!=.,  lcolor(blue) lpattern(dash) xlab(1996(1)2005,labsize(small) angle(45)) ylab(#6,labsize(vsmall) grid) legend(order(1 2) label(1 "Entrants - No Market Experience")  label(2 "Entrants - Market Experience")  size(small) region(lcolor(white)) rows(2) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Number of Entrants",size(vsmall)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(160 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(140 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(175 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving(graphs/entrants.gph,replace))
graph export "graphs/entrants.pdf", as(pdf) fontface(Times) replace
graph export "graphs/entrants.eps", as(eps) fontface(Times) replace
restore
use data_ang,clear
reg entry i.nace##i.ano
predict res_entry,res
table ano mkt_spec_exp,c(mean res_entry)
collapse (mean) res_entry,by(ano mkt_spec_exp)
twoway (line res_entry ano if mkt_spec_exp==0,  lcolor(cranberry) lpattern(solid)) || (line res_entry ano if mkt_spec_exp>0 & mkt_spec_exp!=.,  lcolor(blue) lpattern(dash) xlab(1996(1)2005,labsize(small) angle(45)) ylab(#6,labsize(vsmall) grid) legend(order(1 2) label(1 "Entrants - No Market Experience")  label(2 "Entrants - Market Experience")  size(small) region(lcolor(white)) rows(2) pos(6)) graphregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white) lcolor(white) margin(zero) ilpattern(blank) lpattern(blank) lstyle(none)) plotregion(fcolor(white) ifcolor(white) ilcolor(white) icolor(white)) ytitle("Average Residual Entry Rate",size(vsmall)) xtitle(Year,size(small)) xline(1998,lpattern(dot)) xline(1999,lpattern(dot)) xline(2002,lpattern(dot)) text(160 1998 "Full-scale fighting resumes", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center)) text(140 1999 "UN ends its" "peacekeeping mission", color(cranberry) width(25) size(vsmall) orientation(horizontal) justification(center))  text(175 2002  "February - Savimbi sudden death" "Ceasefire agreement", color(blue) width(25) size(vsmall) orientation(horizontal) justification(center)) saving(graphs/entry_rate.gph,replace))
graph export "graphs/entry_rate.pdf", as(pdf) fontface(Times) replace
graph export "graphs/entry_rate.eps", as(eps) fontface(Times) replace

use manager_regressions_exp, clear
// Number of managers with export experience to Angola
// Aggregate plot
preserve
sort nss ano
gen man_sw_ang = nss==nss[_n-1] & empresa!=empresa[_n-1] & manager==1 & manager[_n-1]==1 & exp_8[_n-1]==1
sort nss ano
gen man_ang = nss==nss[_n-1] & manager==1 & manager[_n-1]==1 & exp_8[_n-1]==1
sort nss ano
gen man_sw = nss==nss[_n-1] & empresa!=empresa[_n-1] & manager==1 & manager[_n-1]==1 & exp_8[_n-1]==0 & exp_8==0
sort nss ano
gen man = nss==nss[_n-1] & manager==1 & manager[_n-1]==1 & exp_8[_n-1]==0 & exp_8==0
collapse (sum) man_* man,by(ano)
gen sw_rate_ang = man_sw_ang/man_ang
gen sw_rate = man_sw/man
twoway (line sw_rate_ang ano) || (line sw_rate ano)
restore
// Regression
use summarystats_wageb, clear
sort nss ano
keep if manager==1 & manager[_n-1]==1 & nss==nss[_n-1]
sort nss ano
gen switch = nss==nss[_n-1] & empresa!=empresa[_n-1]
sort nss ano
gen exp_ang = nss==nss[_n-1] & exp_8[_n-1]==1
foreach o of numlist 1998/2000 2002/2005 {
gen yd`o' = ano>=`o'
gen yd`o'_ang = (ano>=`o')*exp_ang
}
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label"
local icontrols = "age age2 educ_yrs ten manager firm2 firm3 firm4 firm5 firm6 firm7 firm8 firm9 mgfirm2 mgfirm3 mgfirm4 mgfirm5 mgfirm6 mgfirm7 mgfirm8 mgfirm9"
local fcontrols = "relsize aprod PT_exports ln_firmage foreign sh_skilled sh_skilled_d prev_size_d prev_prod_d prev_sec_d prev_size prev_prod prev_secs prev_secd d_age_mg d_educ_mg relmeanwk_age relsdwk_age relmeanwk_educ relsdwk_educ"
local inter_e_tb =  "dsten_exp13 dsten_exp46 dsten_exp79 mg_exp13 mg_exp46 mg_exp79 new_exporter cont_exporter exit_exporter other_exporter"
local iano = "iano1 iano2 iano3 iano4 iano5 iano6 iano7 iano8"
local jobloc = "jobloc1 jobloc2 jobloc3 jobloc4 jobloc5 jobloc6 jobloc7 jobloc8 jobloc9 jobloc10 jobloc11 jobloc12 jobloc13 jobloc14 jobloc15 jobloc16 jobloc17 jobloc18 jobloc19 jobloc20 jobloc21 jobloc22 jobloc23 jobloc24 jobloc25 jobloc26 jobloc27 jobloc28"
local ds_nace = "ds_n2_15 ds_n2_16 ds_n2_17 ds_n2_18 ds_n2_19 ds_n2_20 ds_n2_21 ds_n2_22 ds_n2_23 ds_n2_24 ds_n2_25 ds_n2_26 ds_n2_27 ds_n2_28 ds_n2_29 ds_n2_30 ds_n2_31 ds_n2_32 ds_n2_33 ds_n2_34 ds_n2_35 ds_n2_36 ds_n2_37"
reg switch `icontrols' `fcontrols' yd1998 yd1999* yd2000* yd2002* yd2003* yd2004* yd2005* exp_ang,robust
local instruct "tex(pretty frag) tdec(3) rdec(3) auto(3) bdec(3) sdec(3) symbol($^a$,$^b$,$^c$) se label"
local icontrols = "age age2 educ_yrs ten manager firm2 firm3 firm4 firm5 firm6 firm7 firm8 firm9 mgfirm2 mgfirm3 mgfirm4 mgfirm5 mgfirm6 mgfirm7 mgfirm8 mgfirm9"
local fcontrols = "relsize aprod PT_exports ln_firmage foreign sh_skilled sh_skilled_d prev_size_d prev_prod_d prev_sec_d prev_size prev_prod prev_secs prev_secd d_age_mg d_educ_mg relmeanwk_age relsdwk_age relmeanwk_educ relsdwk_educ"
local inter_e_tb =  "dsten_exp13 dsten_exp46 dsten_exp79 mg_exp13 mg_exp46 mg_exp79 new_exporter cont_exporter exit_exporter other_exporter"
local iano = "iano1 iano2 iano3 iano4 iano5 iano6 iano7 iano8"
local jobloc = "jobloc1 jobloc2 jobloc3 jobloc4 jobloc5 jobloc6 jobloc7 jobloc8 jobloc9 jobloc10 jobloc11 jobloc12 jobloc13 jobloc14 jobloc15 jobloc16 jobloc17 jobloc18 jobloc19 jobloc20 jobloc21 jobloc22 jobloc23 jobloc24 jobloc25 jobloc26 jobloc27 jobloc28"
local ds_nace = "ds_n2_15 ds_n2_16 ds_n2_17 ds_n2_18 ds_n2_19 ds_n2_20 ds_n2_21 ds_n2_22 ds_n2_23 ds_n2_24 ds_n2_25 ds_n2_26 ds_n2_27 ds_n2_28 ds_n2_29 ds_n2_30 ds_n2_31 ds_n2_32 ds_n2_33 ds_n2_34 ds_n2_35 ds_n2_36 ds_n2_37"
cap drop __000000
logit switch `icontrols' `fcontrols' yd1998 yd1999* yd2000* yd2002* yd2003* yd2004* yd2005* exp_ang,robust
margins, dydx(yd1998 yd1999* yd2000* yd2002* yd2003* yd2004* yd2005* exp_ang)



use manager_regressions_exp, clear
keep if manager==1
reg hwage i.nace
predict res_wage,res
replace res_wage = exp(res_wage)
collapse (mean) res_wage,by(ano exp_8)
replace res_wage = log(res_wage)
twoway (line res_wage ano if exp_8==0, sort) || (line res_wage ano if exp_8==1, sort legend(order(1 2) label(1 "no exp") label(2 "exp")))

*/

log close
